home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ccdl150l.zip / IO / GETS.C < prev    next >
C/C++ Source or Header  |  1996-07-26  |  274b  |  20 lines

  1. #include <stdio.h>
  2.  
  3. char *gets(char *buf)
  4. {
  5.     int i = 0,rv;
  6.     while (1) {
  7.         rv = fgetc(stdin);
  8.         if (rv == EOF)
  9.             break;
  10.         buf[i++] = (char)rv;
  11.         if (rv == '\n') 
  12.             break;
  13.     }
  14.     if (!i)
  15.         i = 1;
  16.     buf[i-1] = 0;
  17.     if (rv == EOF)
  18.         return 0;
  19.     else return buf;
  20. }